package org.pisces.wechat.commons.exception;

public class GlobalException extends RuntimeException{

	private static final long serialVersionUID = 4239281056091042550L;
	
	private int errorCode = 100000;

	public GlobalException(int errorCode) {
		this(errorCode, null, null);
	}
	
	public GlobalException(int errorCode, String message){
		this(errorCode, message, null);
	}
	
	public GlobalException(int errorCode, Throwable cause){
		this(errorCode, null, cause);
	}
	
	public GlobalException(String message){
		this(100000, message, null);
	}
	
	public GlobalException(String message, Throwable cause){
		this(100000, message, cause);
	}
	
	public GlobalException(int errorCode, String message, Throwable cause) {
		super(message, cause);
		this.errorCode = errorCode;
	}

	public GlobalException(Throwable cause) {
		this(100000, null, cause);
	}

	public int getErrorCode() {
		return errorCode;
	}

	@Override
	public String getMessage() {
		String message = super.getMessage();
		if(null!=message&&!"".equals(message)){
			return message;
		}
		if(0!=this.errorCode){
			return ErrorCode.getErrorMessage(this.errorCode);
		}
		return "";
	}

	@Override
	public String toString() {
		return "GlobalException [errorCode=" + errorCode + ", message="
				+ getMessage() + "]";
	}
}